<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    template="/templates/template.xhtml">

    <ui:define name="topo">Consulta de Usuário</ui:define>

    <ui:define name="meio">
        <p:panel header="Consulta de Usuário">

            <p:dataTable value="#{beanUsuario.listaUsuarios}" var="usu"
                         emptyMessage="Nenhum usuário cadastrado"
                         id="listagem">

                <p:column headerText="Código:">
                    <h:outputText value="#{usu.id}"/>
                </p:column>

                <p:column headerText="Email">
                    <h:outputText value="#{usu.email}"/>
                </p:column>
                
                <p:column headerText="Nome">
                    <h:outputText value="#{usu.nome}"/>
                </p:column>
                
                <p:column headerText="Apelido">
                    <h:outputText value="#{usu.apelido}"/>
                </p:column>

                <p:column>
                    <h:form>
                        <p:commandButton image="ui-icon ui-icon-pencil" 
                                         title="Editar" ajax="false"
                                         action="#{beanUsuario.alterar(usu)}"/>
                        
                        <p:commandButton image="ui-icon ui-icon-close"
                                         title="Excluir"
                                         onclick="confDelete.show();">
                            <f:setPropertyActionListener value="#{usu}"
                                                         target="#{beanUsuario.usuario}"/>
                        </p:commandButton>
                    </h:form>

                </p:column>
            </p:dataTable>

            <h:form>
                <p:commandButton value="Novo Usuário" 
                                 action="#{beanUsuario.novo()}"
                                 ajax="false"/>
                <p:commandButton value="Pagina Inicial" 
                                 action="#{beanUsuario.paginaIncial()}"
                                 ajax="false"/>
            </h:form>
            
            <p:confirmDialog message="Deseja realmente exlcuir o registro?"
                             width="400" header="Excluir"
                             widgetVar="confDelete">
                <h:form>
                    <p:commandButton value="Sim" 
                                     actionListener="#{beanUsuario.excluir()}"
                                     update=":listagem" 
                                     oncomplete="confDelete.hide()"/>
                    <p:commandButton value="Não" type="button"
                                     onclick="confDelete.hide()"/>
                </h:form>
            </p:confirmDialog>

        </p:panel>
    </ui:define>
</ui:composition>

